﻿@{
    ViewBag.Title = "Home Page";
}

<div class="jumbotron">
    <div class="page-cache-state">This page is </div>
    <div class="page-render-time">It took XXX ms to render this page.</div>
    <div>This page was cached at @DateTime.UtcNow.ToString("G")</div>
    @{
        for (int i = 0; i < 1000; i++)
        {
            <div>The current time is @Html.SupplantContent(() => DateTime.UtcNow.ToString("G"))</div>
        }
    }
</div>

<script type="text/javascript">
    $(document).ready(function() {
        $(".page-render-time")
            .html('It took @Html.SupplantContent(() =>
                   {
                       TimeSpan timeElapsed = MvcApplication.GetRequestTimerElapsed();
                       double milliseconds = timeElapsed.Ticks / (double)TimeSpan.TicksPerMillisecond;
                       return milliseconds.ToString("###,#0.0000") + "ms to render this page.";
                   })');
        var cacheState = "@Html.SupplantContent(() => HttpContext.Current.Response.Headers.AllKeys.Contains(SupplantOutputCacheAttribute.OutputCacheHeaderKey) ? "Cached" : "Uncached")";
        $(".page-cache-state").append($("<span>").addClass(cacheState == "Cached" ? "text-success" : "text-danger").html(cacheState));
    });
</script>